/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cl.zeke.pizzastore.negocio.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author taller
 */
@Entity
@Table(name = "COMPRA_INGREDIENTE")
@NamedQueries({
    @NamedQuery(name = "CompraIngrediente.findAll", query = "SELECT c FROM CompraIngrediente c"),
    @NamedQuery(name = "CompraIngrediente.findByIdCompra", query = "SELECT c FROM CompraIngrediente c WHERE c.compraIngredientePK.idCompra = :idCompra"),
    @NamedQuery(name = "CompraIngrediente.findByIdIngrediente", query = "SELECT c FROM CompraIngrediente c WHERE c.compraIngredientePK.idIngrediente = :idIngrediente"),
    @NamedQuery(name = "CompraIngrediente.findByCantidad", query = "SELECT c FROM CompraIngrediente c WHERE c.cantidad = :cantidad"),
    @NamedQuery(name = "CompraIngrediente.findByPrecioUnitario", query = "SELECT c FROM CompraIngrediente c WHERE c.precioUnitario = :precioUnitario")})
public class CompraIngrediente implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CompraIngredientePK compraIngredientePK;
    @Basic(optional = false)
    @Column(name = "CANTIDAD")
    private int cantidad;
    @Basic(optional = false)
    @Column(name = "PRECIO_UNITARIO")
    private int precioUnitario;
    @JoinColumn(name = "ID_COMPRA", referencedColumnName = "ID_COMPRA", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Compra compra;
    @JoinColumn(name = "ID_INGREDIENTE", referencedColumnName = "ID_INGREDIENTE", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Ingrediente ingrediente;

    public CompraIngrediente() {
    }

    public CompraIngrediente(CompraIngredientePK compraIngredientePK) {
        this.compraIngredientePK = compraIngredientePK;
    }

    public CompraIngrediente(CompraIngredientePK compraIngredientePK, int cantidad, int precioUnitario) {
        this.compraIngredientePK = compraIngredientePK;
        this.cantidad = cantidad;
        this.precioUnitario = precioUnitario;
    }

    public CompraIngrediente(long idCompra, long idIngrediente) {
        this.compraIngredientePK = new CompraIngredientePK(idCompra, idIngrediente);
    }

    public CompraIngredientePK getCompraIngredientePK() {
        return compraIngredientePK;
    }

    public void setCompraIngredientePK(CompraIngredientePK compraIngredientePK) {
        this.compraIngredientePK = compraIngredientePK;
    }

    public int getCantidad() {
        return cantidad;
    }

    public void setCantidad(int cantidad) {
        this.cantidad = cantidad;
    }

    public int getPrecioUnitario() {
        return precioUnitario;
    }

    public void setPrecioUnitario(int precioUnitario) {
        this.precioUnitario = precioUnitario;
    }

    public Compra getCompra() {
        return compra;
    }

    public void setCompra(Compra compra) {
        this.compra = compra;
    }

    public Ingrediente getIngrediente() {
        return ingrediente;
    }

    public void setIngrediente(Ingrediente ingrediente) {
        this.ingrediente = ingrediente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (compraIngredientePK != null ? compraIngredientePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CompraIngrediente)) {
            return false;
        }
        CompraIngrediente other = (CompraIngrediente) object;
        if ((this.compraIngredientePK == null && other.compraIngredientePK != null) || (this.compraIngredientePK != null && !this.compraIngredientePK.equals(other.compraIngredientePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cl.zeke.pizzastore.negocio.entities.CompraIngrediente[ compraIngredientePK=" + compraIngredientePK + " ]";
    }
    
}
